from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
#使用时先注释掉验证码的代码
class TestCase(object):
    def __init__(self):
        self.driver =webdriver.Edge()
        self.driver.get(r'http://localhost:8080/main.html')



    def test(self):
        self.driver.find_element(By.ID, '_easyui_tree_29').click()#进入客户管理界面
        sleep(2)
        iframe = self.driver.find_element(By.XPATH,'//*[@id="tabs"]/div[2]/div[2]/div/iframe')
        self.driver.switch_to.frame(iframe)

        # 输入框
        input=self.driver.find_element(By.ID,'s_name')
        input.send_keys("家乐福")
        sleep(1)

        # 搜索按钮
        self.driver.find_element(By.CSS_SELECTOR,"#tb > div > a:nth-child(5)").click()

        # 添加
        # button=self.driver.find_element(By.CSS_SELECTOR,"#tb > div > a:nth-child(1)")
        # button.click()

        tbody=self.driver.find_element(By.CSS_SELECTOR,"body > div.panel.datagrid.panel-htop.easyui-fluid > div.datagrid-wrap.panel-body > div.datagrid-view > div.datagrid-view2 > div.datagrid-body > table")
        tr_content = tbody.find_elements(By.TAG_NAME, "tr")
        td_content = []
        for tr in tr_content:
            td_content += tr.find_elements(By.TAG_NAME, "td")
        for td in td_content:#输出表格结果
            print(td.text, end="\t")
            a = 0
            a = a + 1
            if(a==6):#换行
                print("")
                a=0

    def login(self):#登录
        self.driver.find_element(By.ID,'userName').send_keys("admin")
        sleep(1)
        self.driver.find_element(By.ID,"password").send_keys("admin123")
        sleep(2)
        self.driver.find_element(By.ID, "loginBtn").click()
        sleep(2)

    def close(self):#退出
        self.driver.close()



case =TestCase()
case.login()
case.test()
sleep(20)
case.close()
